home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / bessel.src < prev    next >
Text File  |  1991-10-19  |  18KB  |  672 lines

  1. %%HP: T(3)A(D)F(.);
  2. DIR
  3. @ BESSEL by Mark A. Ordal
  4. @ ----------------------------------------------------------------------
  5. @
  6. @                J (x), Y (x), I (x), and K (x)
  7. @                 n      n      n          n
  8. @
  9. @ ----------------------------------------------------------------------
  10. @  Integer order Bessel Functions of the first and second kinds and
  11. @  integer order Modified Bessel Functions of the first and second kinds
  12. @  for non-negative integer order and non-negative real argument.
  13. @ ----------------------------------------------------------------------
  14. @ HP48 programs by Dr. Mark A. Ordal, North Dakota State University,
  15. @ Physics Department, Fargo, ND, 58105
  16. @ NU123952@NDSUVM1
  17. @ revision of April 25, 1991
  18. @ ----------------------------------------------------------------------
  19. @ This is the ASCII listing (translate 3 mode) of a directory that
  20. @ contains the following:
  21. @
  22. @    Programs:
  23. @        Jnx, NRJN, ASJ1, and ASJ0      (Bessel: first kind)
  24. @        Ynx, NRYN, ASY1, and ASY0      (Bessel: second kind)
  25. @        Inx, NRIN, ASI1, and ASI0      (Modified Bessel: first kind)
  26. @        Knx, NRKN, ASK1, and ASK0      (Modified Bessel: second kind)
  27. @
  28. @    Subroutines: JYIK, JY1, and JY0
  29. @
  30. @ NOTE: These programs do not prevent you from entering an invalid order
  31. @       or argument.
  32. @
  33. @ When named BESSINT, running the Bytes command on the name of this
  34. @ directory returns:  Checksum  #18596 and 4558 bytes.
  35. @ ----------------------------------------------------------------------
  36. @ Changes from previous version:
  37. @   1) Programs ASJ0, ASJ1, ASY0, and ASY1 preserve the state of system
  38. @      flags (e.g., the DEG or RAD modes).
  39. @
  40. @   2) Subroutine JYIK was made 4.5 bytes smaller by using a START-NEXT
  41. @      LOOP instead of a FOR-NEXT loop.
  42. @ ----------------------------------------------------------------------
  43. Jnx
  44. @ ----------------------------------------------------------------------
  45. @ Bessel Functions of the FIRST kind and integer order
  46. @
  47. @ To use:
  48. @ Level 2 of stack: order (a nonnegative integer)
  49. @ Level 1 of stack: argument (any nonnegative real number)
  50. @
  51. @ When named Jnx, the BYTES command returns #51151 and 123.5 bytes
  52. @ ----------------------------------------------------------------------
  53.   Jnx
  54.     \<< \-> n x
  55.       \<<
  56.         CASE n 0
  57. SAME
  58.           THEN x
  59. ASJ0
  60.           END n 1
  61. SAME
  62.           THEN x
  63. ASJ1
  64.           END n x
  65. NRJN
  66.         END
  67.       \>>
  68.     \>>
  69.   Ynx
  70. @ ----------------------------------------------------------------------
  71. @ Bessel Functions of the SECOND kind and integer order
  72. @
  73. @ To use:
  74. @ Level 2 of stack: order (a nonnegative integer)
  75. @ Level 1 of stack: argument (any positive real number)
  76. @
  77. @ Remember that Yn(x) is infinite for x=0
  78. @
  79. @ When named Ynx, the BYTES command returns #18975 and 123.5 bytes
  80. @ ----------------------------------------------------------------------
  81.     \<< \-> n x
  82.       \<<
  83.         CASE n 0
  84. SAME
  85.           THEN x
  86. ASY0
  87.           END n 1
  88. SAME
  89.           THEN x
  90. ASY1
  91.           END n x
  92. NRYN
  93.         END
  94.       \>>
  95.     \>>
  96.   Inx
  97. @ ----------------------------------------------------------------------
  98. @ Modified Bessel Functions of the FIRST kind and integer order
  99. @
  100. @ To use:
  101. @ Level 2 of stack: order (a nonnegative integer)
  102. @ Level 1 of stack: argument (any nonnegative real number)
  103. @
  104. @ When named Inx, the BYTES command returns #30214d and 123.5 bytes
  105. @ ----------------------------------------------------------------------
  106.     \<< \-> n x
  107.       \<<
  108.         CASE n 0
  109. SAME
  110.           THEN x
  111. ASI0
  112.           END n 1
  113. SAME
  114.           THEN x
  115. ASI1
  116.           END n x
  117. NRIN
  118.         END
  119.       \>>
  120.     \>>
  121.   Knx
  122. @ ----------------------------------------------------------------------
  123. @ Modifed Bessel Functions of the SECOND kind and integer order
  124. @
  125. @ To use:
  126. @ Level 2 of stack: order (a nonnegative integer)
  127. @ Level 1 of stack: argument (any positive real number)
  128. @
  129. @ Remember that Kn(x) is infinite for x=0
  130. @
  131. @ When named Knx, the BYTES command returns #20615d and 123.5 bytes
  132. @ ----------------------------------------------------------------------
  133.     \<< \-> n x
  134.       \<<
  135.         CASE n 0
  136. SAME
  137.           THEN x
  138. ASK0
  139.           END n 1
  140. SAME
  141.           THEN x
  142. ASK1
  143.           END n x
  144. NRKN
  145.         END
  146.       \>>
  147.     \>>
  148.   NRJN
  149. @ ----------------------------------------------------------------------
  150. @ Bessel Functions of the FIRST kind and integer order n > 1
  151. @ calculated using the RPL equivalent of the "Numerical Recipes"
  152. @ program BESSJ.  Needs the equivalent of the "Numerical Recipes"
  153. @ programs BESSJ0 and BESSJ1.  In this case, programs ASJ0 and ASJ1
  154. @ are used instead -- based on Abramowitz and Stegun Eqs 9.4.1 and
  155. @ 9.4.3 for order zero and Eqs 9.4.4 and 9.4.6 for order one.
  156. @
  157. @ The programs ASJ0 and ASJ1 based on the Abramowitz and Stegun
  158. @ equations are shorter and faster than RPL equivalents of BESSJ0
  159. @ and BESSJ1.)
  160. @
  161. @ To use:
  162. @ Level 2 of stack: order (a positive integer > 1)
  163. @ Level 1 of stack: argument (any nonnegative real number)
  164. @
  165. @ The "Numerical Recipes" program variables TOX, SUM, BIGNO, BIGNI,
  166. @ and BESSJ have been replaced by t, s, u, d, and sj, respectively.
  167. @ Variable IACC has been replaced by its value of 40.
  168. @
  169. @ When named NRJN, the BYTES command returns #18067d and 657 bytes
  170. @
  171. @ To adapt for use on the HP28S, replace the commands 'm' DECR with
  172. @ the equivalent sequence m 1 - 'm' STO m
  173. @ ----------------------------------------------------------------------
  174.     \<< 10000000000
  175. .0000000001 0 0 0 0
  176. \-> n x u d t m s sj
  177.       \<< 2 x / 't'
  178. STO
  179.         IF x n >
  180.         THEN x ASJ0
  181. x ASJ1 1 n 1 -
  182.           FOR j j t
  183. * OVER * 3 PICK -
  184. ROT DROP
  185.           NEXT SWAP
  186. DROP
  187.         ELSE 40 n *
  188. \v/ IP n + 2 / IP 2 *
  189. 'm' STO 0 1 m
  190.           DO t *
  191. OVER * 3 PICK - ROT
  192. DROP
  193.             IF DUP
  194. ABS u >
  195.             THEN d
  196. * SWAP d * SWAP d
  197. DUP 'sj' STO* 's'
  198. STO*
  199.             END
  200.             IF m n
  201. SAME
  202.             THEN
  203. OVER 'sj' STO
  204.             END 'm'
  205. DECR t * OVER * 3
  206. PICK - ROT DROP
  207.             IF DUP
  208. ABS u >
  209.             THEN d
  210. * SWAP d * SWAP d
  211. DUP 'sj' STO* 's'
  212. STO*
  213.             END
  214.             IF m n
  215. SAME
  216.             THEN
  217. OVER 'sj' STO
  218.             END DUP
  219. 's' STO+ 'm' DECR
  220.           UNTIL m 1
  221. <
  222.           END DROP
  223. SWAP DROP NEG s 2 *
  224. + sj SWAP /
  225.         END
  226.       \>>
  227.     \>>
  228.   NRYN
  229. @ ----------------------------------------------------------------------
  230. @ Bessel Functions of the SECOND kind and integer order n > 1
  231. @ calculated using the RPL equivalent of the "Numerical Recipes"
  232. @ program BESSY.  Needs the equivalent of the "Numerical Recipes"
  233. @ programs BESSY0 and BESSY1.  In this case, programs ASY0 and ASY1
  234. @ are used instead -- based on Abramowitz and Stegun Eqs 9.4.1 and
  235. @ 9.4.3 for order zero and Eqs 9.4.4 and 9.4.6 for order one.
  236. @
  237. @ The programs ASY0 and ASY1 based on the Abramowitz and Stegun
  238. @ equations are shorter and faster than RPL equivalents of BESSY0
  239. @ and BESSY1.)
  240. @
  241. @ To use:
  242. @ Level 2 of stack: order (a positive integer > 1)
  243. @ Level 1 of stack: argument (any positive real number)
  244. @
  245. @ The "Numerical Recipes" program variable TOX has been replaced by t.
  246. @ Variable IACC has been replaced by its value of 40.
  247. @
  248. @ When named NRYN, the BYTES command returns #16760 and 143 bytes
  249. @ ----------------------------------------------------------------------
  250.     \<< 0 \-> n x t
  251.       \<< 2 x / 't'
  252. STO x ASY0 x ASY1 1
  253. n 1 -
  254.         FOR j j t *
  255. OVER * 3 PICK - ROT
  256. DROP
  257.         NEXT SWAP
  258. DROP
  259.       \>>
  260.     \>>
  261.   NRIN
  262. @ ----------------------------------------------------------------------
  263. @ Modified Bessel Functions of the FIRST kind and integer order n > 1
  264. @ calculated using the RPL equivalent of the "Numerical Recipes"
  265. @ program BESSI.  Needs the equivalent of the "Numerical Recipes"
  266. @ programs BESSI0 and BESSI1.  These programs (renamed ASJ0 and ASJ1)
  267. @ are based on Abramowitz and Stegun Eqs 9.8.1 and 9.8.2 for order zero
  268. @ and Eqs 9.8.3 and 9.8.4 for order one.
  269. @
  270. @ To use:
  271. @ Level 2 of stack: order (a positive integer > 1)
  272. @ Level 1 of stack: argument (any nonnegative real number)
  273. @
  274. @ The "Numerical Recipes" program variables TOX, BIGNO, BIGNI,
  275. @ and BESSI have been replaced by t, u, d, and si, respectively.
  276. @ Variable IACC has been replaced by its value of 40.
  277. @
  278. @ When named NRIN, the BYTES command returns #9623d and 315 bytes
  279. @ ----------------------------------------------------------------------
  280.     \<< 10000000000
  281. .0000000001 0 0 \-> n
  282. x u d t si
  283.       \<< 2 x / 't'
  284. STO 0 1 40 n * \v/ IP
  285. n + 2 * 1
  286.         FOR j j t *
  287. OVER * 3 PICK + ROT
  288. DROP
  289.           IF DUP
  290. ABS u >
  291.           THEN d *
  292. SWAP d * SWAP d
  293. 'si' STO*
  294.           END
  295.           IF j n
  296. SAME
  297.           THEN OVER
  298. 'si' STO
  299.           END -1
  300.         STEP SWAP
  301. DROP si SWAP / x
  302. ASI0 *
  303.       \>>
  304.     \>>
  305.   NRKN
  306. @ ----------------------------------------------------------------------
  307. @ Modifed Bessel Functions of the SECOND kind and integer order n > 1
  308. @ calculated using the RPL equivalent of the "Numerical Recipes"
  309. @ program BESSK.  Needs the equivalent of the "Numerical Recipes"
  310. @ programs BESSK0 and BESSK1.  These programs (renamed ASK0 and ASK1)
  311. @ are based on Abramowitz and Stegun Eqs 9.8.5 and 9.8.6 for order zero
  312. @ and Eqs 9.8.7 and 9.8.8 for order one.
  313. @
  314. @ To use:
  315. @ Level 2 of stack: order (a positive integer > 1)
  316. @ Level 1 of stack: argument (any positive real number)
  317. @
  318. @ The "Numerical Recipes" program variables TOX, BIGNO, BIGNI,
  319. @ and BESSK have been replaced by t, u, d, and sk, respectively.
  320. @
  321. @ When named NRKN, the BYTES command returns #20286d and 181 bytes
  322. @ ----------------------------------------------------------------------
  323.     \<< 10000000000
  324. .0000000001 0 0 \-> n
  325. x u d t sk
  326.       \<< 2 x / 't'
  327. STO x ASK0 x ASK1 1
  328. n 1 -
  329.         FOR j j t *
  330. OVER * 3 PICK + ROT
  331. DROP
  332.         NEXT SWAP
  333. DROP
  334.       \>>
  335.     \>>
  336.   ASJ1
  337. @ ----------------------------------------------------------------------
  338. @ Bessel Functions of t4e FIRST kind and order one calculated
  339. @ using Abramowitz and Stegun Eqs 9.4.4 and 9.4.6
  340. @
  341. @ This program is slightly shorter and faster than the RPL equivalent
  342. @ of the "Numerical Recipes" program BESSJ1.
  343. @
  344. @ This program program calls programs JYIK and JY1.
  345. @
  346. @ To use:
  347. @ Level 1 of stack: argument (any nonnegative real number)
  348. @
  349. @ When named ASJ1, the BYTES command returns #49835d and 213.5 bytes
  350. @ ----------------------------------------------------------------------
  351.     \<< 0 RCLF \-> x a
  352. ff
  353.       \<<
  354.         IF x 3 <
  355.         THEN .5
  356. -.56249985
  357. .21093573
  358. -.03954289
  359. .00443319
  360. -.00031761
  361. .00001109 x 3 / SQ
  362. 6 JYIK x *
  363.         ELSE x JY1
  364. RAD COS * x \v/ /
  365.         END ff STOF
  366.       \>>
  367.     \>>
  368.   ASY1
  369. @ ----------------------------------------------------------------------
  370. @ Bessel Functions of the SECOND kind and order one calculated
  371. @ using Abramowitz and Stegun Eqs 9.4.4 and 9.4.6
  372. @
  373. @ This program is slightly shorter and faster than the RPL equivalent
  374. @ of the "Numerical Recipes" program BESSY1.
  375. @
  376. @ This program program calls programs JYIK, JY1, and ASJ1.
  377. @
  378. @ To use:
  379. @ Level 1 of stack: argument (any positive real number)
  380. @
  381. @ When named ASY1, the BYTES command returns #1027d and 270 bytes
  382. @ ----------------------------------------------------------------------
  383.     \<< 0 RCLF \-> x a
  384. ff
  385.       \<<
  386.         IF x 3 <
  387.         THEN
  388. -.6366198 .2212091
  389. 2.1682709
  390. -1.3164827 .3123951
  391. -.0400976 .0027873
  392. x 3 / SQ 6 JYIK x
  393. ASJ1 x .5 * LN * x
  394. * 2 * \pi \->NUM / + x
  395. /
  396.         ELSE x JY1
  397. RAD SIN * x \v/ /
  398.         END ff STOF
  399.       \>>
  400.     \>>
  401.   ASI1
  402. @ ----------------------------------------------------------------------
  403. @ Modifed Bessel Functions of the FIRST kind and order one calculated
  404. @ using Abramowitz and Stegun Eqs 9.8.3 and 9.8.4
  405. @
  406. @ To use:
  407. @ Level 1 of stack: argument (any nonnegative real number)
  408. @
  409. @ This program program calls program JYIK
  410. @
  411. @ When named ASI1, the BYTES command returns #12477d and 334.5 bytes
  412. @ ----------------------------------------------------------------------
  413.     \<< 0 \-> x a
  414.       \<<
  415.         IF x ABS
  416. 3.75 <
  417.         THEN .5
  418. .87890594 .51498869
  419. .15084934 .02658733
  420. .00301532 .00032411
  421. x 3.75 / SQ 6 JYIK
  422. x *
  423.         ELSE
  424. .39894228
  425. -.03988024
  426. -.00362018
  427. .00163801
  428. -.01031555
  429. .02282967
  430. -.02895312
  431. .01787654
  432. -.00420059 3.75 x
  433. ABS / 8 JYIK x ABS
  434. DUP EXP SWAP \v/ / *
  435.         END
  436.       \>>
  437.     \>>
  438.   ASK1
  439. @ ----------------------------------------------------------------------
  440. @ Modifed Bessel Functions of the SECOND kind and order one calculated
  441. @ using Abramowitz and Stegun Eqs 9.8.7 and 9.8.8
  442. @
  443. @ This program program calls programs JYIK and ASI1.
  444. @
  445. @ To use:
  446. @ Level 1 of stack: argument (any positive real number)
  447. @
  448. @ When named ASK1, the BYTES command returns #54561d and 308 bytes
  449. @ ----------------------------------------------------------------------
  450.     \<< 0 \-> x a
  451.       \<<
  452.         IF x ABS 2
  453. <
  454.         THEN 1
  455. .15443144
  456. -.67278579
  457. -.18156897
  458. -.01919402
  459. -.00110404
  460. -.00004686 x 2 / SQ
  461. 6 JYIK x / x ASI1 x
  462. 2 / LN * +
  463.         ELSE
  464. 1.25331414
  465. .23498619 -.0365562
  466. .01504268
  467. -.00780353
  468. .00325614
  469. -.00068245 2 x / 6
  470. JYIK x DUP NEG EXP
  471. SWAP \v/ / *
  472.         END
  473.       \>>
  474.     \>>
  475.   ASJ0
  476. @ ----------------------------------------------------------------------
  477. @ Bessel Functions of the FIRST kind and order zero calculated
  478. @ using Abramowitz and Stegun Eqs 9.4.1 and 9.4.3
  479. @
  480. @ This program is slightly shorter and faster than the RPL equivalent
  481. @ of the "Numerical Recipes" program BESSJ0.
  482. @ This program program calls programs JYIK and JY0.
  483. @
  484. @ To use:
  485. @ Level 1 of stack: argument (any nonnegative real number)
  486. @
  487. @ When named ASJ0, the BYTES command returns #1504d and 198.5 bytes
  488. @ ----------------------------------------------------------------------
  489.     \<< 0 RCLF \-> x a
  490. ff
  491.       \<<
  492.         IF x 3 <
  493.         THEN 1
  494. -2.2499997
  495. 1.2656208 -.3163866
  496. .0444479 -.0039444
  497. .00021 x 3 / SQ 6
  498. JYIK
  499.         ELSE x JY0
  500. RAD COS * x \v/ /
  501.         END ff STOF
  502.       \>>
  503.     \>>
  504.   ASY0
  505. @ ----------------------------------------------------------------------
  506. @ Bessel Functions of the SECOND kind and order zero calculated
  507. @ using Abramowitz and Stegun Eqs 9.4.1 and 9.4.3
  508. @
  509. @ This program is slightly shorter and faster than the RPL equivalent
  510. @ of the "Numerical Recipes" program BESSY0.
  511. @ This program program calls programs JYIK, JY0, and ASJ0.
  512. @
  513. @ To use:
  514. @ Level 1 of stack: argument (any nonnegative real number)
  515. @
  516. @ When named ASY0, the BYTES command returns #37606d and 256 bytes
  517. @ ----------------------------------------------------------------------
  518.     \<< 0 RCLF \-> x a
  519. ff
  520.       \<<
  521.         IF x 3 <
  522.         THEN
  523. .36746691 .60559366
  524. -.74350384
  525. .25300117
  526. -.04261214
  527. .00427916
  528. -.00024846 x 3 / SQ
  529. 6 JYIK x ASJ0 x .5
  530. * LN * 2 * \pi \->NUM /
  531. +
  532.         ELSE x JY0
  533. RAD SIN * x \v/ /
  534.         END ff STOF
  535.       \>>
  536.     \>>
  537.   ASI0
  538. @ ----------------------------------------------------------------------
  539. @ Modifed Bessel Functions of the FIRST kind and order zero calculated
  540. @ using Abramowitz and Stegun Eqs 9.8.1 and 9.8.2
  541. @
  542. @ To use:
  543. @ Level 1 of stack: argument (any nonnegative real number)
  544. @
  545. @ This program program calls program JYIK
  546. @
  547. @ When named ASI0, the BYTES command returns #63274 and 319.5 bytes
  548. @ ----------------------------------------------------------------------
  549.     \<< 0 \-> x a
  550.       \<<
  551.         IF x ABS
  552. 3.75 <
  553.         THEN 1
  554. 3.5156229 3.0899424
  555. 1.2067492 .2659732
  556. .0360768 .0045813 x
  557. 3.75 / SQ 6 JYIK
  558.         ELSE
  559. .39894228 .01328592
  560. .00225319
  561. -.00157565
  562. .00916281
  563. -.02057706
  564. .02635537
  565. -.01647633
  566. .00392377 3.75 x
  567. ABS / 8 JYIK x ABS
  568. DUP EXP SWAP \v/ / *
  569.         END
  570.       \>>
  571.     \>>
  572.   ASK0
  573. @ ----------------------------------------------------------------------
  574. @ Modifed Bessel Functions of the SECOND kind and order zero calculated
  575. @ using Abramowitz and Stegun Eqs 9.8.5 and 9.8.6
  576. @
  577. @ This program program calls programs JYIK and ASI0.
  578. @
  579. @ To use:
  580. @ Level 1 of stack: argument (any positive real number)
  581. @
  582. @ When named ASK0, the BYTES command returns #64307 and 311.5 bytes
  583. @ ----------------------------------------------------------------------
  584.     \<< 0 \-> x a
  585.       \<<
  586.         IF x ABS 2
  587. <
  588.         THEN
  589. -.57721566 .4227842
  590. .23069756 .0348859
  591. .00262698 .0001075
  592. .0000074 x 2 / SQ 6
  593. JYIK x ASI0 x 2 /
  594. LN NEG * +
  595.         ELSE
  596. 1.25331414
  597. -.07832358
  598. .02189568
  599. -.01062446
  600. .00587872 -.0025154
  601. .00053208 2 x / 6
  602. JYIK x DUP NEG EXP
  603. SWAP \v/ / *
  604.         END
  605.       \>>
  606.     \>>
  607.   JYIK
  608. @ ----------------------------------------------------------------------
  609. @ Subprogram for use by ASJ0, ASJ1, ASY0, ASY1, ASI0, ASI1, ASK0, and
  610. @ ASK1
  611. @
  612. @ When named JYIK, the BYTES command returns #32125d and 56.5 bytes
  613. @ ----------------------------------------------------------------------
  614.     \<< \-> t j
  615.       \<< 1 j
  616.         START t * +
  617.         NEXT
  618.       \>>
  619.     \>>
  620.   JY1
  621. @ ----------------------------------------------------------------------
  622. @ Subprogram for use by ASJ1 and ASY1
  623. @
  624. @ This program program calls program JYIK
  625. @
  626. @ When named JY1, the BYTES command returns #54172d and 241 bytes
  627. @ ----------------------------------------------------------------------
  628.     \<< 0 \-> x a
  629.       \<< 3 x / 'a'
  630. STO .79788456
  631. .00000156 .01659667
  632. .00017105
  633. -.00249511
  634. .00113653
  635. -.00020033 a 6 JYIK
  636. -2.35619449
  637. .12499612 .0000565
  638. -.00637879
  639. .00074348 .00079824
  640. -.00029166 a 6 JYIK
  641. x +
  642.       \>>
  643.     \>>
  644.   JY0
  645. @ ----------------------------------------------------------------------
  646. @ Subprogram for use by ASJ0 and ASY0
  647. @
  648. @ This program program calls program JYIK
  649. @
  650. @ When named JY0.SUB, the BYTES command returns #15249d and 241 bytes
  651. @ ----------------------------------------------------------------------
  652.     \<< 0 \-> x a
  653.       \<< 3 x / 'a'
  654. STO .79788456
  655. -.00000077
  656. -.0055274
  657. -.00009512
  658. .00137237
  659. -.00072805
  660. .00014476 a 6 JYIK
  661. -.78539816
  662. -.04166397
  663. -.00003954
  664. .00262573
  665. -.00054125
  666. -.00029333
  667. .00013558 a 6 JYIK
  668. x +
  669.       \>>
  670.     \>>
  671. END
  672.